package com.xiao.train.business.controller.admin;

import com.xiao.train.business.service.DailyTrainService;
import com.xiao.train.common.resp.CommonResp;
import com.xiao.train.business.req.DailyTrainQueryReq;
import com.xiao.train.business.req.DailyTrainSaveReq;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("admin/daily-train")
public class DailyTrainAdminController {

    @Autowired
    DailyTrainService dailyTrainService;

    @PostMapping("save")
    public CommonResp save(@Valid @RequestBody DailyTrainSaveReq req) {
        dailyTrainService.save(req);
        return new CommonResp();
    }

    @GetMapping("query-list")
    public CommonResp queryList(@Valid DailyTrainQueryReq req) {
        return new CommonResp(dailyTrainService.queryList(req));
    }

    @GetMapping("gen-daily/{date}")
    public CommonResp genDaily(
            @PathVariable
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
        dailyTrainService.genDaily(date);
        return new CommonResp();
    }

    @DeleteMapping("delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        dailyTrainService.delete(id);
        return new CommonResp();
    }
}